package com.sinothk.view.refresh.demo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.sinothk.banner.nice.Banner
import com.sinothk.banner.nice.BannerConfig
import com.sinothk.banner.nice.Transformer
import com.sinothk.view.xrefresh.XRefreshView


class XRefreshDemoMainActivity : AppCompatActivity() {
    var bannerView: Banner? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

//        val xRefreshLayout: XRefreshLayout = findViewById(R.id.xRefreshLayout)
        bannerView = findViewById(R.id.bannerView)
//
//
//        val headerView = HeaderView(this, R.color.bg, R.color.graye)
//        //        HeaderView headerView = new HeaderView(this, R.color.bg, R.color.graye, R.drawable.refresh_progress_style_img);
//        xRefreshLayout.setHeaderView(headerView)
//        val footerView = FooterView(this, R.color.bg, R.color.graye, ProgressStyle2Bar(this))
//        xRefreshLayout.setFooterView(footerView)
//        xRefreshLayout.setRefreshEnable(true)
//        xRefreshLayout.setLoadMoreEnable(false)
//
////        public class CustomView extends QLoadView
////        public class CustomView implements ILoadView
//
//        qrefreshLayout.setHeaderView(new CustomView());
//        qrefreshLayout.setFooterView(new CustomView());
//        xRefreshLayout.setRefreshHandler(object : RefreshHandler {
//            override fun onRefresh(refresh: XRefreshLayout) {
//                Handler().postDelayed({ runOnUiThread { xRefreshLayout.refreshComplete() } }, 3000)
//            }
//
//            override fun onLoadMore(refresh: XRefreshLayout) {
//                Handler().postDelayed({ runOnUiThread { xRefreshLayout.loadMoreComplete() } }, 3000)
//            }
//        })

        val refreshLayout: XRefreshView = findViewById(R.id.refreshLayout)
        refreshLayout.setRefreshHeader(ClassicsHeader(this))
        refreshLayout.setRefreshFooter(ClassicsFooter(this))
        refreshLayout.setOnRefreshListener { refreshlayout ->
            refreshlayout.finishRefresh()
//            refreshlayout.finishRefresh(2000, true, true) //传入false表示刷新失败
        }
        refreshLayout.setOnLoadMoreListener { refreshlayout ->
            refreshlayout.finishLoadMore(2000 /*,false*/) //传入false表示加载失败
        }

        refreshLayout.autoRefresh()

        initBannerView()
    }

    /**
     * 轮播图
     */
    private fun initBannerView() {
        val bannerList: ArrayList<CustomData> = ArrayList()

        for (index in 0..3) {
            bannerList.add(CustomData("https://t7.baidu.com/it/u=2529476510,3041785782&fm=193&f=GIF"))
        }

        bannerView!!.setAutoPlay(true)
                .setPages(bannerList, CustomViewHolder())
                .setBannerStyle(BannerConfig.CIRCLE_INDICATOR)
                .setBannerAnimation(Transformer.Default)
                .setDelayTime(3000)
                .start()

        bannerView!!.setOnBannerClickListener { _, position ->

        }
    }
}